<!DOCTYPE html>

<html lang="zh-Hans">
  <head>
    <meta charset="utf-8" />
    <meta name="author" content="rogepi" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="/style.css" />
    <script src="/vue.global.js"></script>
    <title>2-attribute-inherit</title>
  </head>

  <body>
    <div id="attribute-inherit">
      <date-picker @change="showChange"></date-picker>
    </div>
    <script>
      const app = Vue.createApp({
        methods: {
          showChange(event) {
            console.log(event.target.value);
          },
        },
      });

      // 当组件返回单个根节点时，非 prop attribute 将自动添加到根节点的 attribute 中。
      // 例如，在 <date-picker> 组件的实例中：
      app.component('date-picker', {
        template: `
          <select>
            <option value="1">Yesterday</option>
            <option value="2">Today</option>
            <option value="3">Tomorrow</option>
          </select>`,
        created() {
          // 同样的规则也适用于事件监听器：
          console.log(this.$attrs);
        },
      });

      app.mount('#attribute-inherit');
    </script>
  </body>
</html>
